import { usePeFile } from "./hooks/pe.ts";

/**
 * @author tongxin
 * @date 2024/4/23 11:23
 */
export class StringTableRecord {
  LENGTH = 6 as const;
  length: number;
  valueLength: number;
  type: number;
  key: string;
  value: string;
  offset: number;
  padding: number;

  constructor(byteArray: IByteArray, offset: number) {
    const {calculatePadding, readString} = usePeFile()
    this.offset = offset;
    this.length = byteArray.readWord();
    this.valueLength = byteArray.readWord();
    this.type = byteArray.readWord();
    this.key = readString(byteArray);
    offset = byteArray.getOffset();
    offset = offset + calculatePadding(offset);
    byteArray.setOffset(offset);
    this.value = readString(byteArray).trim();
    this.padding = calculatePadding(this.offset + this.length - 2);
  }

  getEndOffset(): number {
    return offset + length - 2 + padding;
  }
}
